package com.thyrsus.project.form.user;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.thyrsus.project.object.UserContext;

public class UserForm implements Serializable {

	private static final long serialVersionUID = 1L;

	private String login;
	private String password;
	private String passwordConfirm;
	private String firstName;
	private String lastName;
	private String mail;
	private String dayBirthDate;
	private String monthBirthDate;
	private String yearBirthDate;
	private String phone;
	
	private String locale;
	
	private List<Integer>days;
	private List<Integer>months;
	private List<Integer>years;
	
	private String ajaxResult;
	
	public UserForm(UserContext user) {
		this.login = user.getLogin();
		this.password = user.getPassword();
		this.firstName = user.getFirstName().toUpperCase();
		this.lastName = user.getLastName().toUpperCase();
		this.mail = user.getMail();
		//this.birthDate = user.getBirthDate();
		Calendar cal = GregorianCalendar.getInstance();
		try {
			cal.setTime(user.getBirthDate());
			dayBirthDate = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
			monthBirthDate = String.valueOf(cal.get(Calendar.MONTH));
			yearBirthDate = String.valueOf(cal.get(Calendar.YEAR));
		} catch(Exception e) {
			
		}
		this.phone = user.getPhone();
		this.locale = user.getLocale();
		setDates();
	}
	
	public UserForm() {
		setDates();
	}
	
	private void setDates(){
		days = new ArrayList<Integer>();
		for (int i = 0 ; i < 31 ; i++) {
			days.add(i+1);
		}
		months = new ArrayList<Integer>();
		for (int i = 0 ; i < 12 ; i++) {
			months.add(i+1);
		}
		years = new ArrayList<Integer>();
		for (int i = 1909 ; i < 2010 ; i++) {
			years.add(i+1);
		}
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPasswordConfirm() {
		return passwordConfirm;
	}
	public void setPasswordConfirm(String passwordConfirm) {
		this.passwordConfirm = passwordConfirm;
	}
	public String getAjaxResult() {
		return ajaxResult;
	}
	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}
	public Date getBirthDate() {
		Calendar cal = GregorianCalendar.getInstance();
		try {
			cal.set(Integer.valueOf(getYearBirthDate()).intValue(),
					Integer.valueOf(getMonthBirthDate()).intValue(),
					Integer.valueOf(getDayBirthDate()).intValue());
		} catch(Exception e) {
			return null;
		}
		return cal.getTime();
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getDayBirthDate() {
		return dayBirthDate;
	}
	public void setDayBirthDate(String dayBirthDate) {
		this.dayBirthDate = dayBirthDate;
	}
	public String getMonthBirthDate() {
		return monthBirthDate;
	}
	public void setMonthBirthDate(String monthBirthDate) {
		this.monthBirthDate = monthBirthDate;
	}
	public String getYearBirthDate() {
		return yearBirthDate;
	}
	public void setYearBirthDate(String yearBirthDate) {
		this.yearBirthDate = yearBirthDate;
	}
	public List<Integer> getDays() {
		return days;
	}
	public void setDays(List<Integer> days) {
		this.days = days;
	}

	public List<Integer> getMonths() {
		return months;
	}
	public void setMonths(List<Integer> months) {
		this.months = months;
	}
	public List<Integer> getYears() {
		return years;
	}
	public void setYears(List<Integer> years) {
		this.years = years;
	}

	public String getLocale() {
		return locale;
	}

	public void setLocale(String locale) {
		this.locale = locale;
	}
}
